<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"   label-width="72px" >
      <el-form-item label="产品类别" prop="productType">
        <el-select v-model="queryParams.productType" placeholder="请选择产品类别" >
          <el-option
            v-for="dict in dict.type.product_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
        />

      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini"
                   @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary" :disabled="single"  @click="changeProduct()">确认</el-button>
        <el-button type="danger"   @click="closeProduct">取消选中</el-button>
      </el-form-item>
    </el-form>
    <el-table :row-style="{ height: '30px' }"  :cell-style="{ padding: '0px' }" height="450" border v-loading="loading" :data="qualificationList" @row-click="handleRowClick"
              :row-key="getRowKey" :highlight-current-row="false" :current-row-key="selectedRowId" highlight-current-row>
      <el-table-column
        label="序号"
        type="index"
        :index="indexMethod"/>
      <el-table-column label="产品类别" align="center" prop="productType" :show-overflow-tooltip="true" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.product_type" :value="scope.row.productType"/>
        </template>
      </el-table-column>
      <el-table-column label="产品编号" align="left" prop="productNo" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="产品名称" align="left" prop="productName" :show-overflow-tooltip="true" width="150"/>
      <el-table-column label="产品介绍" align="left" prop="productRemark" :show-overflow-tooltip="true" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import { listChange,changeQualification} from "@/api/qualificationInfo/qualification";
export default {
  name: "changeProduct",
  dicts: ['product_type', 'product_status','customer_industry', 'administrative_area','qualification_resume_status'],
  created() {
    this.getList();
  },
  data(){
    return{
      // 遮罩层
      loading: true, // 在这里定义loading属性
      qualificationList:[],
      total:0,
      selectedRow: null, // 用于存储选中的行数据
      selectedRowId:null,
      // 非多个禁用
      single: true,
      queryParams:{
        pageNum:1,
        pageSize:5,
        productType:null,
        productName:null
      }
    }
  },
  methods:{
    getList(){
      listChange(this.queryParams).then(res=>{
        this.qualificationList = res.rows;
        this.total = res.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.productName=null
      this.queryParams.productType=null
      this.selectedRow=null
      this.handleQuery();
    },
    // 单选行点击事件
    handleRowClick(row) {
      this.selectedRow = row;
      this.single = false; // 取消禁用确认按钮
    },
    //确认
    changeProduct(){
      if (this.selectedRow)  {
        changeQualification([this.selectedRow.id]).then(res=>{
          this.getList();
          this.$emit('product', res.data);
          this.selectedRowId = this.selectedRow.id; // 设置当前行的 key，实现高亮
        });
      }
    },
    // 获取行的 key
    getRowKey(row, index) {
      return row.id; // 假设行数据中有 id 字段作为 key
    },
    //取消选择
    closeProduct(){
      this.selectedRowId=null
      this.selectedRow=null
      this.$emit('closeProduct', false);
    },
  }
}
</script>
<style >

</style>
